﻿Imports System.Data
Imports System.Data.Odbc
Imports WSEntidades
Imports MySql.Data.MySqlClient
Imports Utilerias

Public Class CDonatariasFact
    Public Shared Function Build(ByVal dr As MySqlDataReader) As CDonatariasBE
        Dim tmpDonatarias As CDonatariasBE = New CDonatariasBE()
        tmpDonatarias.Donataria = New DONAT_11.Donatarias
        Dim dtfi As System.Globalization.DateTimeFormatInfo = New System.Globalization.DateTimeFormatInfo
        Try
            With tmpDonatarias
                While dr.Read()
                    If (Conversiones.convertSNToBool(convertDTFromDb.ConvertString(dr.Item("Status")))) Then
                        .Status = CDonatariasBE.EstatusDonat.Activa
                    Else
                        .Status = CDonatariasBE.EstatusDonat.Inactiva
                    End If
                    .RegimenFiscal = (convertDTFromDb.ConvertString(dr.Item("RegimenFiscal")))
                    If (dr.Item("CveConfig") = "Version") Then
                        .Donataria.version = convertDTFromDb.ConvertString(dr.Item("Valor"))
                    End If
                    If (dr.Item("CveConfig") = "NumAut") Then
                        .Donataria.noAutorizacion = convertDTFromDb.ConvertString(dr.Item("Valor"))
                    End If
                    If (dr.Item("CveConfig") = "FechaAut") Then
                        dtfi.ShortDatePattern = "dd-MM-yyyy"
                        dtfi.DateSeparator = "-"
                        .Donataria.fechaAutorizacion = Convert.ToDateTime(convertDTFromDb.ConvertString(dr.Item("Valor")), dtfi)
                    End If
                    If (dr.Item("CveConfig") = "Leyenda") Then
                        .Donataria.leyenda = convertDTFromDb.ConvertString(dr.Item("Valor"))
                    End If
                End While
            End With
            Return tmpDonatarias
        Catch ex As Exception
            Throw
        Finally
            dtfi = Nothing
            tmpDonatarias = Nothing
        End Try
    End Function

End Class
